/*
 * CDBRenderer.java
 *
 * Copyright (c) 2009 Giles Millward (Manigra). All rights reserved.
 *
 * This file is part of JRogueDPS.
 *
 * JRogueDPS is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * JRogueDPS is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with JRogueDPS.  If not, see <http://www.gnu.org/licenses/>.
 */

package geardatabase;

import geardatabase.CItem;
import java.awt.Color;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.border.Border;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author Mani
 */
public class CDBRenderer extends JLabel
                           implements TableCellRenderer {
    Border unselectedBorder = null;
    Border selectedBorder = null;
    boolean isBordered = true;

    public CDBRenderer(boolean isBordered) {
        this.isBordered = isBordered;
        setOpaque(true); //MUST do this for background to show up.
    }

    public Component getTableCellRendererComponent(
                            JTable table, Object p_dbItem,
                            boolean isSelected, boolean hasFocus,
                            int row, int column) {
        CItem l_dbItem = (CItem) p_dbItem;
        if (l_dbItem == null)
        {

            this.setText("");
            this.setBackground(Color.WHITE);
            this.setIcon(null);
            return this;
        }

        setBackground(Color.WHITE);

        if (l_dbItem.getGemType() != null)
        {
            this.setIcon(CGemType.getGemImage(l_dbItem.getGemType()));
        }
        
        this.setText(l_dbItem.getName());
        this.setToolTipText("<html>" + l_dbItem.getHtmlTooltip() + "</html>");
        this.setBackground(CItemQuality.getBackColor(l_dbItem.getGearQuality()));
        this.setFont(new java.awt.Font("Arial Narrow", 0, 12));

        return this;
    }
}
